<template>
	<view class="container">
		<header class="box">
			<img src="../../static/head.png" alt="Head Image" class="head-image" />
			<view style="height: 10px"></view>
		</header>
		<ul class="box tabs ">
			<li :class="['noactive', { 'active': activeTab === 0 }]" @click="setActiveTab(0)">
				翻倍红包
			</li>
			<li :class="['noactive', { 'active': activeTab === 1 }]" @click="setActiveTab(1)">
				天天领红包
			</li>
			<li :class="['noactive', { 'active': activeTab === 2 }]" @click="setActiveTab(2)">
				限时会场
			</li>
		</ul>
		<main>
			<view class="tab-content">
					<Tab1 v-if="activeTab === 0"/>
					<Tab2 v-if="activeTab === 1"/>
					<Tab3 v-if="activeTab === 2"/>
				<!-- <router-view></router-view> -->
			</view>
		</main>
	</view>
</template>

<script>
	import { queryStringToObject} from '../../utils/eleutil.js'
	import {inspectEle} from "@/api/userchannel.js";

	export default {
		data() {
			return {
				activeTab: 0,
			};
		},
		components: {
			Tab1: () => import("../tab1/tab1.vue"),
			Tab2: () => import("../tab2/tab2.vue"),
			Tab3: () => import("../tab3/tab3.vue")
		},
		mounted() {
			this.activeTab = 0; // 初始化展示tab1
			const url = window.location.href;
			//分享
			if (this.$wechat && this.$wechat.isWechat()) {
				this.$wechat.share({
					title: '饿了么红包合集',
					desc: "饿了么红包天天领，您有一个外卖红包待领取，最高20元！",
					img: 'https://tp.juzicps.com/juzicps/images/20230828/1693212487966_ele.png'
				}, url);
			}

			const params = queryStringToObject(window.location.href);
			console.info('params======>' + params.sid)
			let sid = params.sid
			if (sid) {
				this.inspect(sid)
			} else {
				uni.showToast({
					title: '参数不完整!',
					icon: 'none',
					duration: 2000
				});
			}
		},
		methods: {
			setActiveTab(index) {
				this.activeTab = index;
			},
			inspect(sid) {
				inspectEle(sid).then((res) => {
					if (res.code == 200) {
						if (!res.data) {
							console.log("获取SID失败");
							uni.showToast({
								title: 'sid无效!',
								icon: 'none',
								duration: 2000
							});
						}
						console.log("获取SID", res.data);
					} else {
						console.log("获取SID失败");
						uni.showToast({
							title: 'code无效!',
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			
		},
	};
</script>

<style scoped>
	.container {
		display: flex;
		flex-direction: column;
		height: 100vh;
		width: 100%;
		background-color: #F7F7FA;
	}

	header {
		height: 100px;
	}

	.head-image {
		width: 100%;
		object-fit: cover;
		border-radius: 20px;
	}

	nav {
		height: 40px;
		background-color: #eaeaea;
	}

	.box {
		width: 96vw;
		margin: 0 2vw;
	}

	.tabs {
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 100%;
		list-style: none;
		list-style-type: none;
		padding: 0;
		margin-bottom: 10px;
		background-color: #fff;
		border-radius: 10px;
	}

	.tabs li {
		display: inline-block;
		height: 40px;
		line-height: 40px;
		padding: 0 10px;
		cursor: pointer;
		font-size: 14px;
		font-weight: 700;
	}

	.tabs li.active {
		position: relative;
      color: #2a82e4;
	  box-shadow: 0 1px 5px #2a82e4;
	border-radius: 10px;
      /*box-shadow: inset 0 0 5px #2a82e4, 0 2px 5px #2a82e4;*/
	}

	.tabs li.noactive::after {
		content: "";
		background-color: rgba(229, 229, 229, 1);
		/* 滑块的颜色 */
		height: 2px;
		width: 25px;
		position: absolute;
		bottom: 6px;
		left: calc(50% - 12.5px);
		/* 将滑块居中 */
	}

	.tabs li.active::after {
		background-color: #2a82e4 !important;
		/* 滑块的颜色 */
	}

	main {
		flex-grow: 1;
	}

	.tab-content {
		height: calc(100vh - 150px);
		max-width: 98%;
		overflow: hidden;
		overflow-y: auto;
	}
</style>